import { useState, useEffect } from 'react';

export function useMainHeight(config: { idName?: string; className?: string }) {
	const { idName, className } = config;
	const [height, setHeight] = useState(0);
	useEffect(() => {
		if (idName) {
			const ele = document.getElementById(idName);
			ele && setHeight(Math.floor(ele.clientHeight));
		} else if (className) {
			const ele = document.getElementsByClassName(className);
			if (ele.length > 1) {
				console.error('检测到多个相同的"className"');
			} else {
				setHeight(ele[0].clientHeight);
			}
		}
	}, []);

	return [height];
}
